package com.bw.liuyushan.liuyushan20210904.Utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.bw.liuyushan.liuyushan20210904.Managers.App;

/**
 * Liuyushan20210904
 * file name is : SPUtils
 * created by Ender on 2021/9/4 12:01.
 * author : 刘雨杉
 * Describe:双重单例锁封装Sp工具类
 */
public class SPUtils {
    private SharedPreferences sp;
    SharedPreferences.Editor edit;
    private static SPUtils spUtils;

    public static SPUtils getInstance() {
        if (spUtils==null){
            synchronized (SPUtils.class){
                if (spUtils==null){
                    spUtils=new SPUtils();
                }
            }
        }
        return spUtils;
    }

    private SPUtils() {

        sp = App.context.getSharedPreferences("sp", Context.MODE_PRIVATE);
        edit = sp.edit();
    }
    public void put(String name,Object o){
        if (o instanceof Boolean){
            edit.putBoolean(name,true);
        }
        edit.commit();
    }

    public SharedPreferences getSp() {
        return sp;
    }

    public SharedPreferences.Editor getEdit() {
        return edit;
    }
}
